<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ProtoBufferTest</title>
</head>
<body>

</body>

<script src="./protobuf.js"></script>
<script src="./mspb.js"></script>
<script src="./msutil.js"></script>



<script type="text/javascript">

    var message = new proto.stream.JoinRoomReq();
    message.setGameid(200948);
    message.setJointype(proto.stream.JoinRoomType.JOINRANDOMROOM);
    message.setCpproto("userProfile");

    var keyvalues = new proto.stream.keyValue();
    keyvalues.setKey("name");
    keyvalues.setValue("geliang");
    message.addTags(keyvalues);

    var playinfo = new proto.stream.PlayerInfo();
    playinfo.setUserid(524548);
    playinfo.setUserprofile("userProfile");
    message.setPlayerinfo(playinfo);

    console.log(message);

    var bytes = message.serializeBinary();
    console.log(bytes);

    var data = proto.stream.LoginReq.deserializeBinary(bytes);
    console.log(data);


    var WSMessage;
    protobuf.load("./test.proto", function (err, root) {
        if (err) throw err;
        console.log(root);
        WSMessage = root.lookup("jsproto.WSMessage");

        var msgCheckInNotify = WSMessage.create({ id:1, content: "hello",
            sender: new Uint8Array(8), time: [1,2,3,4],
            keyValue:root.lookup("jsproto.keyValue").create([{key:"1",value:"1"},{key:"2",value:"2"}]) });

        console.log("tojson:"+msgCheckInNotify.toJSON());



        var buffer = WSMessage.encode(msgCheckInNotify).finish();
        var msg = WSMessage.decode(buffer);
        console.log("msg:"+msg);
    });
     </script>
</html>